
//
//  HMStatusDetailFrame.m
//  黑马微博-wzy
//
//  Created by Mac on 2017/2/17.
//  Copyright © 2017年 Mac. All rights reserved.
//

#import "HMStatusDetailFrame.h"
#import "HMStatusOriginalFrame.h"
#import "HMStatusRetweetedFrame.h"
#import "HMStatus.h"


@interface HMStatusDetailFrame()

@property (nonatomic, assign) CGFloat h;

@end

@implementation HMStatusDetailFrame

//根据传进来的微博数据计算frame
//重写 status 的setter 方法
- (void)setStatus:(HMStatus *)status{
    _status = status;
    
    //1.计算原创微博的frame
    [self calculateOriginalFrame];
    //2.计算转发微博的frame
    [self calculateRetweetedFrame];
    //3.计算自己的frame
    [self calculateDetailFrame];
}


//1.计算原创微博的frame
- (void)calculateOriginalFrame{
    HMStatusOriginalFrame *originalFrame = [[HMStatusOriginalFrame alloc] init];
    //把微博数据传入 HMStatusOriginalFrame
    originalFrame.status = _status;
    self.originalFrame = originalFrame;

}

//2.计算转发微博的frame
- (void)calculateRetweetedFrame{
    CGFloat h = 0;
    //如果有转发微博
    if (_status.retweeted_status) {
        HMStatusRetweetedFrame *retweetedFrame = [[HMStatusRetweetedFrame alloc] init];
        //把微博数据传入 HMStatusRetweetedFrame
        retweetedFrame.retweetedStatus = _status.retweeted_status;
        //计算转发微博frame 的y值
        CGRect f = retweetedFrame.retweetedF;
        f.origin.y = CGRectGetMaxY(_originalFrame.originalF);
        retweetedFrame.retweetedF = f;
        
        self.retweetedFrame = retweetedFrame;
        
        h = CGRectGetMaxY(retweetedFrame.retweetedF);
    }else{
    
        h = CGRectGetMaxY(_originalFrame.originalF);
    }
    
    _h = h;
}

//3.计算自己的frame
- (void)calculateDetailFrame{
    CGFloat x = 0;
    CGFloat y = HMStatusCellMargin;
    CGFloat w = kScreenWidth;
    self.detailF = CGRectMake(x, y, w, _h);

}


@end
